package com.uenpay.im.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.provider.MediaStore.Images.Thumbnails;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qyx.android.weight.choosemorepic.PhotoAibum;
import com.uenpay.im.R;

import java.util.ArrayList;

/**
 * 
 * @author SL
 * @date 2014/7/24
 * @copyRight http://www.qiyunxin.com
 */
public class ChooseAlbumAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<PhotoAibum> aibumList = new ArrayList<PhotoAibum>();

	public ChooseAlbumAdapter(Context _Context,
			ArrayList<PhotoAibum> _AibumList) {
		mContext = _Context;
		aibumList = _AibumList;
	}

	@Override
	public int getCount() {
		return aibumList.size();
	}

	@Override
	public PhotoAibum getItem(int position) {
		return aibumList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		PhotoAibum aibum = getItem(position);
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.choose_album_list_item, parent,false);
			holder.nameTextView = (TextView) convertView
					.findViewById(R.id.album_name);
			holder.imageView = (ImageView) convertView
					.findViewById(R.id.album_first_image);
			holder.countTextView = (TextView) convertView
					.findViewById(R.id.album_image_count);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}

		Bitmap bitmap = Thumbnails.getThumbnail(mContext
				.getContentResolver(), aibumList.get(position).getBitmap(),
				Thumbnails.MICRO_KIND, null);
		holder.imageView.setImageBitmap(bitmap);
		holder.nameTextView.setText(aibum.getName());
		holder.countTextView.setText("(" + aibum.getCount() + ")");
		return convertView;
	}

	class Holder {
		private ImageView imageView;
		private TextView nameTextView, countTextView;
	}
}
